local gongwei = fk.CreateSkill {
  name = "kl__gongwei",
  tags = { Skill.Limited },
}

Fk:loadTranslationTable{
  ["kl__gongwei"] = "功威",
  [":kl__gongwei"] = "限定技，出牌阶段，你可以摸X张牌，然后回复等量体力并展示所有手牌，若如此做，本回合限两次，你可以令你使用的【杀】或【决斗】额外结算一次或伤害+1（X为游戏的轮次且至多为5）。",

  ["#kl__gongwei"] = "功威：摸%arg张牌，然后回复等量体力并展示所有手牌，若如此做，本回合你可以令你使用的【杀】或【决斗】额外结算一次或伤害+1（限两次）",
  ["@kl__gongwei-turn"] = "功威",
  ["kl__gongwei-effect"] = "额外结算一次",
  ["kl__gongwei-damage"] = "伤害+1",

  ["$kl__gongwei1"] = "踏遍天下谁敌手，自杖银枪辨雌雄。",
  ["$kl__gongwei2"] = "宇内安有无双将，且与子龙试高低。",
}

gongwei:addEffect("active", {
  can_use = function(self, player)
    return player.phase == Player.Play and player:usedEffectTimes(self.name, Player.HistoryGame) == 0
  end,
  card_num = 0,
  card_filter = Util.FalseFunc,
  target_filter = Util.FalseFunc,
  target_num = 0,
  prompt = function ( self, player )
    local x = math.min(Fk:currentRoom():getBanner("RoundCount"), 5)
    return "#kl__gongwei:::"..x
  end,
  on_use = function(self, room, effect)
    local player = effect.from
    local x = math.min(Fk:currentRoom():getBanner("RoundCount"), 5)
    player:drawCards(x, gongwei.name)
    if player.dead then return end
    if player:isWounded() then
      room:recover{ who = player, num = x, skillName = gongwei.name }
    end
    if player.dead then return end
    room:addPlayerMark(player, "@kl__gongwei-turn", 2)
    player:showCards(player:getCardIds("h"))
  end,
})

gongwei:addEffect(fk.CardUsing, {
  mute = true,
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(gongwei.name) and (data.card.trueName == "slash" or data.card.trueName == "duel")
    and player:getMark("@kl__gongwei-turn") > 0 and player:usedEffectTimes(self.name) < 2
  end,
  on_cost = function(self, event, target, player, data)
    local choice = player.room:askToChoice(player, {
      choices = {"Cancel", "kl__gongwei-effect", "kl__gongwei-damage"},
      prompt = "功威：你可以令此 %arg 获得对应效果:::"..data.card:toLogString(),
      skill_name = gongwei.name,
    })
    if choice ~= "Cancel" then
      event:setCostData(self, { choice = choice })
      return true
    end
  end,
  on_use = function (self, event, target, player, data)
    local choice = event:getCostData(self).choice
    player:broadcastSkillInvoke(gongwei.name)
    player.room:doAnimate("InvokeSkill", {
      name = gongwei.name,
      player = player.id,
      skill_type = "offensive",
    })
    if choice == "kl__gongwei-effect" then
      data.additionalEffect = (data.additionalEffect or 0) + 1
    elseif choice == "kl__gongwei-damage" then
      data.additionalDamage = (data.additionalDamage or 0) + 1
    end
    player.room:removePlayerMark(player, "@kl__gongwei-turn")
  end,
})


return gongwei